import service from "../../utils/request.ts";
import type {AxiosPromise} from "axios";
import type {addMenuForm, menuList, parentMenuTree} from "./types.ts";

/**
 * 获取验证码
 * @returns {*}
 */
export const getAllMenu = () => {
    return [
        {
            "path": "/home",
            "name": "home",
            "component": "dept/dept",
            "meta": {
                "title": "首页",
                "icon": "category"
            }
        }, {
            "path": "/system",
            "name": "system",
            "component": "test",
            "meta": {
                "title": "系统管理",
                "icon": "system"
            },
            "children": [
                {
                    "path": "/system/roles",
                    "name": "roles",
                    "component": "dept/dept",
                    "meta": {
                        "title": "权限管理",
                        "icon": "peoples"
                    },
                    "children": [{
                        "path": "/system/roles/user",
                        "name": "user",
                        "component": "dept/dept",
                        "meta": {
                            "title": "用户管理",
                            "icon": "user"
                        }
                    }, {
                        "path": "/system/roles/role",
                        "name": "role",
                        "component": "dept/dept",
                        "meta": {
                            "title": "角色管理",
                            "icon": "people"
                        }
                    }, {
                        "path": "/system/roles/menu",
                        "name": "menu",
                        "component": "menu/menu",
                        "meta": {
                            "title": "菜单管理",
                            "icon": "tree"
                        }
                    },
                        {
                            "path": "/system/roles/tenant",
                            "name": "tenant",
                            "component": "tenant/tenant",
                            "meta": {
                                "title": "租户管理",
                                "icon": "company"
                            }
                        }]
                },
                {
                    "path": "/system/log",
                    "name": "log",
                    "component": "dept/dept",
                    "meta": {
                        "title": "日志管理",
                        "icon": "edit"
                    },
                },
                {
                    "path": "/system/data",
                    "name": "data",
                    "component": "dept/dept",
                    "meta": {
                        "title": "数据统计",
                        "icon": "table"
                    },
                }
            ]
        }, {
            "path": "/exam.ts",
            "name": "exam",
            "component": "dept/dept",
            "meta": {
                "title": "在线考试",
                "icon": "guide"
            }
        }, {
            "path": "/certificate",
            "name": "certificate",
            "component": "dept/dept",
            "meta": {
                "title": "证书管理",
                "icon": "education"
            }
        }


    ]
}


/**
 * 获取父级菜单树
 */
export const getParentMenuList = (): AxiosPromise<parentMenuTree> => {
    return service({
        url: "/menu/getParentMenu",
        method: 'get',
        data: null
    })
}
/**
 * 添加菜单信息
 * @param data
 */
export const addMenuInfos = (data: addMenuForm) => {
    return service({
        url: "/menu/addMenu",
        method: "post",
        data
    })
}

/**
 * 获取菜单列表
 */
export const getMenuList= (menuName:string):AxiosPromise<menuList[]> => {
    return service({
        url: "/menu/getMenuList",
        method: "get",
        params: {
            menuName
        },
        data:null
    })
}

/**
 * 根据id删除菜单
 * @param id
 */
export  const  removeMenu = (id:number) => {
    return service({
        url: `/menu/delete/${id}`,
        method: "delete",
        data: null
    })
}

/**
 * 根据id查询菜单信息
 * @param id
 */
export const getMenuInfoById=(id:number)=>{
    return service({
        url: `/menu/${id}`,
        method: "get",
        data: null
    })
}


/**
 * 修改菜单信息
 * @param data
 */
export const updateMenuInfos = (data: addMenuForm) => {
    return service({
        url: "/menu/update",
        method: "put",
        data
    })
}